home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 November: Tool Chest / Dev.CD Nov 98 TC.toast / Sample Code / Snippets / Development Tools & Languages / Windoid / UWindoid.h < prev    next >
Encoding:
Text File  |  1995-02-13  |  6.1 KB  |  247 lines  |  [TEXT/MPS ]

  1. // UWindoid.h -----------------------------------------------------------------
  2. // Copyright © 1991 by Apple Computer, Inc. All rights reserved.
  3.  
  4.  
  5. // INCLUDE FILES --------------------------------------------------------------
  6.  
  7. #include "IncludeFiles.h"
  8.  
  9.  
  10. //FORWARD DECLARATIONS --------------------------------------------------------
  11.  
  12. class TFloatingMenu;
  13. class TDefaultView;
  14. class TLightPalette;
  15.  
  16.  
  17. // GLOBALS --------------------------------------------------------------------
  18.  
  19. TFloatingMenu*     gFloatingMenu;
  20. TWindow*        gFloatMenuWindow;
  21.  
  22. enum eLights {kGreen=0,kYellow,kRed, kNoTool = 42}; // global values for the lights    
  23.  
  24.  
  25. // CLASS DEFINITIONS-----------------------------------------------------------
  26.  
  27. // TApplication ---------------------------------------------------------------
  28.  
  29. DeclareClassDesc(TWindoidApplication);
  30.  
  31. class TWindoidApplication : public TApplication {
  32.  
  33.     DeclareClass(TWindoidApplication);
  34.  
  35. public:
  36. //    METHODS
  37.     virtual      void         IWindoidApplication(OSType itsMainFileType,
  38.                                                     OSType itsCreator);
  39.     virtual      void            DoSetupMenus();
  40.     virtual      TDocument*     DoMakeDocument(CommandNumber, TFile* itsFile);
  41. };
  42.  
  43.  
  44. // TDocuments -----------------------------------------------------------------
  45.  
  46. DeclareClassDesc(TWindoidDocument);
  47.  
  48. class TWindoidDocument : public TDocument {
  49.  
  50.     DeclareClass(TWindoidDocument);
  51.  
  52. public:
  53. //    METHODS
  54.     virtual      void DoMakeViews(Boolean forPrinting); 
  55.  
  56.     virtual      void    DoSetupMenus();                // setup document menus
  57.     virtual      void DoMenuCommand(CommandNumber aCommandNumber);
  58.     virtual      void DoLight(eLights);            // do Light drawing
  59.  
  60. //    FIELDS    
  61.     TDefaultView*        fView;                        // the view used     
  62. };
  63.  
  64.  
  65. // TViews ---------------------------------------------------------------------
  66.  
  67. DeclareClassDesc(TDefaultView);
  68.  
  69. class TDefaultView : public TView {
  70.  
  71.     DeclareClass(TDefaultView);
  72.  
  73. public:
  74. //    ENUMS AND TYPEDEFS
  75.     enum eCoordinate {ktop=20,kbottom=150,kleft=200,kright=250};
  76.  
  77. //    METHODS
  78.     TDefaultView (); // constructor
  79.     
  80.     virtual      void     Draw(const VRect& area);// general draw method
  81.     virtual      void     DrawTrafficLight();        // draw traffic light body
  82.     virtual      void     DrawLight();            // general light drawing method
  83.     virtual      void     DrawGreen();            // draw green light
  84.     virtual      void     DrawYellow();            // draw yellow light
  85.     virtual      void     DrawRed();                // draw red light
  86.  
  87. //    FIELDS    
  88.     CRect     fTrafficRect;                            // traffic light components
  89.     CRect     fBlackTopRect;
  90.     CRect     fTrafficLightFrame;
  91.     CRect     fGreenRect;
  92.     CRect     fYellowRect;
  93.     CRect     fRedRect;
  94.     CStr255 fTitle;
  95.     eLights    fCurrentLight;
  96. };
  97.  
  98.  
  99. // And now the cool stuff, the TearOff floating window class
  100.  
  101. DeclareClassDesc(TFloatingMenu);
  102.  
  103. class TFloatingMenu : public TTearOffMenuView {
  104.  
  105.     DeclareClass(TFloatingMenu);
  106.  
  107. public:
  108. //    METHODS
  109.     virtual      void IFloatingMenu();        // init floating menu
  110. };
  111.  
  112.  
  113. DeclareClassDesc(TLightPalette);
  114.  
  115. class TLightPalette : public TView {
  116.  
  117.     DeclareClass(TLightPalette);
  118.  
  119. public:
  120. //    METHODS
  121.     
  122.     TLightPalette();
  123.  
  124.     virtual      void ILightPalette(TDocument *itsDocument, TView *itsView);
  125.     
  126.     virtual      void Draw(const VRect &area);    // draw view
  127.     virtual      void Activate(Boolean entering);    // activate view
  128.     
  129.     virtual      void DoMouseCommand       (VPoint& theMouse, TToolboxEvent* event,
  130.                                             CPoint hysteresis);
  131.                                             
  132.     virtual      void TrackFeedback       (TrackPhase         aTrackPhase,
  133.                                             const VPoint&    anchorPoint,
  134.                                             const VPoint&    previousPoint,
  135.                                             const VPoint&    nextPoint,
  136.                                             Boolean            mouseDidMove,
  137.                                             Boolean            turnItOn);
  138.  
  139.     
  140.     virtual      void SelectNewTool(eLights whichTool);
  141.     virtual      void FrameTool(CRect);            // frame the selected tool
  142.     virtual      void BuildChoiceArray();            // build tool array
  143.     virtual      void Toggle();                    // toggle tool selections
  144.     virtual      void DoHighlightSelection(HLState fromHL, HLState toHL);
  145.  
  146. //    FIELDS    
  147.     CRect     fChoiceArray[kLightsInPalette];            // tool array
  148.     eLights    fCurrentTool;                            // tool selection
  149.     eLights    fOldTool;                                // earlier used tool
  150.     eLights    fSelectedTool;                            // currently *selected* tool                        
  151. };
  152.  
  153.  
  154. // TCOMMANDS ------------------------------------------------------------------
  155.  
  156. DeclareClassDesc(TToolSelectCommand);
  157.  
  158. class TToolSelectCommand : public TTearOffMenuViewTracker {
  159.  
  160.     DeclareClass(TToolSelectCommand);
  161.  
  162. public:
  163. //    METHODS
  164.     virtual      void     IToolSelectCommand (TLightPalette*     theToolsPalette,
  165.                                                  TLightPalette*    theMenuToolsPalette,
  166.                                                 TLightPalette*     theFloatingToolsPalette,
  167.                                                 VPoint&         theMouse);
  168.                                             
  169.     virtual       void     DoIt(void);                // execute selection command
  170.     virtual Boolean         IsDoneTracking();        // no more tracking?
  171.  
  172.     virtual         void    TrackFeedback       (TrackPhase         aTrackPhase,
  173.                                                 const VPoint&    anchorPoint,
  174.                                                 const VPoint&    previousPoint,
  175.                                                 const VPoint&    nextPoint,
  176.                                                 Boolean            mouseDidMove,
  177.                                                 Boolean            turnItOn);
  178.                                                 
  179.     virtual      TTracker* TrackMouse           (TrackPhase         aTrackPhase,
  180.                                                 VPoint&            anchorPoint,
  181.                                                 VPoint&            previousPoint,
  182.                                                 VPoint&            nextPoint,
  183.                                                 Boolean            mouseDidMove);
  184.                                                 
  185. //    FIELDS                                                
  186.     eLights            fTool;                            // selected tool
  187.     TLightPalette*    fMenuToolsPalette;                // ptr to Menu Tool view
  188.     TLightPalette*    fFloatingToolsPalette;            // ptr to Floating WIndow view
  189.     Boolean            fExitTracking;                    // keep track of tracking state
  190. };
  191.  
  192.  
  193. DeclareClassDesc(TTrafficCommand);
  194.  
  195. class TTrafficCommand : public TCommand {
  196.  
  197.     DeclareClass(TTrafficCommand);
  198.  
  199. public:
  200. //    METHODS
  201.     TTrafficCommand();
  202.     
  203.     TWindoidDocument* fCommandDocument;                // document attached to command
  204. };
  205.  
  206.  
  207. DeclareClassDesc(TGreenCommand);
  208.  
  209. class TGreenCommand : public TTrafficCommand {
  210.  
  211.     DeclareClass(TGreenCommand);
  212.  
  213. public:
  214. //    METHODS
  215.     virtual      void IGreenCommand(TWindoidDocument*);
  216.     virtual      void DoIt();
  217. };
  218.  
  219.  
  220. DeclareClassDesc(TYellowCommand);
  221.  
  222. class TYellowCommand : public TTrafficCommand {
  223.  
  224.     DeclareClass(TYellowCommand);
  225.  
  226. public:
  227. //    METHODS
  228.     virtual      void IYellowCommand(TWindoidDocument*);
  229.     virtual      void DoIt();
  230. };
  231.  
  232.  
  233. DeclareClassDesc(TRedCommand);
  234.  
  235. class TRedCommand : public TTrafficCommand {
  236.  
  237.     DeclareClass(TRedCommand);
  238.  
  239. public:
  240. //    METHODS
  241.     virtual      void IRedCommand(TWindoidDocument*);
  242.     virtual      void DoIt();
  243. };
  244.  
  245.  
  246. // THE END -------------------------------------------------------------------
  247.